<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<div>
    <h1>登录</h1>
    <span>账号：</span><input id="username" type="text"><br>
    <span>密码：</span><input id="password" type="password"><br>
    <button id="btn1">登录</button>
    <button id="btn2">注册</button>
</div>
<script src="/js/jquery-3.6.0.js"></script>
<!--<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js"></script>-->
<script>
    $("#btn1").click(function (){
        var username=$("#username").val();
        var password=$("#password").val();
        $.ajax({
            url:"/login",
            type:"post",
            data:"username="+username+"&password="+password,
            success:function (data) {
                if(data==1){
                    alert("登录成功");
                    sessionStorage.setItem("username",username);
                    location.href="/admin/manager.html";
                    return;
                }
                if (data==0){
                    alert("登陆失败！用户名不存在！");
                    return;
                }
                if (data==2){
                    alert("登陆失败！密码错误！");
                    return;
                }
            }
        })
    });
        $("#btn2").click(function () {
            location.href="register.html";
        })
</script>
</body>
</html>